﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Data;
using System.Text;
using System.Configuration;

namespace WebBanThuoc.counter
{
    public class dem
    {

        int num = 0;
        string filePath = HttpContext.Current.Server.MapPath("~/counter/counter.txt");
     
        public  int get_counter()
        { 
            num =read_counter();
              //  if(HttpContext.Current.Session["dem"] == null ){
                    num++;
                    write_counter(num.ToString());
                   // HttpContext.Current.Session["dem"] = num;
                
             //   }
          return num;
        }
        public int read_counter()
        {
            int code = 0;
            if (File.Exists(filePath))
            {
                StreamReader r = new StreamReader(filePath);
                code = Convert.ToInt32(r.ReadLine());
                r.Close();
            }
            else
            {
                //("File not found.");
            }
           return code;
        }

        public void write_counter(string code)
        {
           
            FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Unicode);

            sw.WriteLine(code.ToString());

            sw.Flush();
            sw.Close();
            fs.Close();
        }

    }
}